home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / cawf404.zip / output.c < prev    next >
C/C++ Source or Header  |  1993-12-07  |  3KB  |  126 lines

  1. /*
  2.  *    output-c - output support functions for cawf(1)
  3.  */
  4.  
  5. /*
  6.  *    Copyright (c) 1991 Purdue University Research Foundation,
  7.  *    West Lafayette, Indiana 47907.  All rights reserved.
  8.  *
  9.  *    Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue
  10.  *    University Computing Center.  Not derived from licensed software;
  11.  *    derived from awf(1) by Henry Spencer of the University of Toronto.
  12.  *
  13.  *    Permission is granted to anyone to use this software for any
  14.  *    purpose on any computer system, and to alter it and redistribute
  15.  *    it freely, subject to the following restrictions:
  16.  *
  17.  *    1. The author is not responsible for any consequences of use of
  18.  *       this software, even if they arise from flaws in it.
  19.  *
  20.  *    2. The origin of this software must not be misrepresented, either
  21.  *       by explicit claim or by omission.  Credits must appear in the
  22.  *       documentation.
  23.  *
  24.  *    3. Altered versions must be plainly marked as such, and must not
  25.  *       be misrepresented as being the original software.  Credits must
  26.  *       appear in the documentation.
  27.  *
  28.  *    4. This notice may not be removed or altered.
  29.  */
  30.  
  31. #include "cawf.h"
  32.  
  33.  
  34. /*
  35.  * PageInRange(pg) - is page number in printable range?
  36.  */
  37.  
  38. int
  39. PageInRange(pg)                /* page number */
  40.     int pg;
  41. {
  42.     struct pgrange *pr;
  43.  
  44.     if (!PgRange)
  45.         return(1);
  46.     for (pr = PgRange; pr; pr = pr->next) {
  47.         if (pg >= pr->l && pg <= pr->u)
  48.             return(1);
  49.     }
  50.     return(0);
  51. }
  52.  
  53.  
  54. /*
  55.  * LenprtHF(s, p, t, b) - get length of print header or footer with page
  56.  *              number interpolation
  57.  */
  58.  
  59. LenprtHF(s, p, t, b)
  60.     unsigned char *s;        /* header/footer string */
  61.     int p;                /* page number */
  62.     int t;                /* type: 0 = get interpolated length
  63.                      *     1 = print */
  64.     unsigned char **b;        /* optional buffer address pointer */
  65. {
  66.     unsigned char buf[10];        /* buffer for page number */
  67.     int len;            /* line length */
  68.     unsigned char *s1;        /* temporary string pointer */
  69.     
  70.     if (s == NULL)
  71.         return(0);
  72.     for (len = 0; *s && *s != '%'; s++) {
  73.         len++;
  74.         if (t) {
  75.             if ( ! b) {
  76.                 Charput(s);
  77.             } else {
  78.                 **b = *s;
  79.                 (*b)++;
  80.             }
  81.         }
  82.     }
  83.     if (*s) {
  84.         (void) sprintf((char *)buf, "%d", p);
  85.         for (s1 = buf; *s1; s1++) {
  86.             len++;
  87.             if (t) {
  88.                 if (! b) {
  89.                     Charput(s1);
  90.                 } else {
  91.                     **b = *s1;
  92.                     (*b)++;
  93.                 }
  94.             }
  95.         }
  96.         for (s++; *s; s++) {
  97.             len++;
  98.             if (t) {
  99.                 if ( ! b) {
  100.                     Charput(s);
  101.                 } else {
  102.                     **b = *s;
  103.                     (*b)++;
  104.                 }
  105.             }
  106.         }
  107.     }
  108.     return(len);
  109. }
  110.  
  111.  
  112. /*
  113.  * Stringput(s) - put a string to output, subject to diversion
  114.  */
  115.  
  116. void
  117. Stringput(s, l)
  118.     unsigned char *s;    /* string to put */
  119.     int l;            /* length */
  120. {
  121.     int i;
  122.  
  123.     if (!Divert && Pageprt)
  124.         (void) fwrite(s, l, 1, stdout);
  125. }
  126.